package com.cruise.game.model.param.common;

import com.cruise.game.common.constants.CommonConstants;
import lombok.Data;

import java.io.Serializable;

/**
 * 分页查询参数
 * 
 * @author cruise
 * @date 2025-02-28
 */
@Data
public class PageQueryParam implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 页码
     */
    private Integer page = CommonConstants.DEFAULT_PAGE_NUM;

    /**
     * 每页条数
     */
    private Integer pageSize = CommonConstants.DEFAULT_PAGE_SIZE;

    /**
     * 排序字段
     */
    private String sortBy;

    /**
     * 排序方向
     */
    private String sortOrder = CommonConstants.SORT_ASC;

    /**
     * 获取分页起始位置
     *
     * @return 分页起始位置
     */
    public Integer getOffset() {
        return (page - 1) * pageSize;
    }

    /**
     * 限制最大页面大小
     */
    public void limitPageSize() {
        if (this.pageSize > CommonConstants.MAX_PAGE_SIZE) {
            this.pageSize = CommonConstants.MAX_PAGE_SIZE;
        }
    }
}
